home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 November / SGI Freeware 1999 November - Disc 1.iso / dist / fw_expect.idb / usr / freeware / catman / u_man / cat1 / autoexpect.Z / autoexpect
Text File  |  1999-01-26  |  9KB  |  265 lines

  1.  
  2.  
  3.  
  4.      AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))     UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((33330000 JJJJuuuunnnneeee 1111999999995555))))     AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       autoexpect - generate    an Expect script from watching a
  10.       session
  11.  
  12.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.       aaaauuuuttttooooeeeexxxxppppeeeecccctttt [ _a_r_g_s ] [    _p_r_o_g_r_a_m    _a_r_g_s...    ]
  14.  
  15.      IIIINNNNTTTTRRRROOOODDDDUUUUCCCCTTTTIIIIOOOONNNN
  16.       autoexpect watches you interacting with another program and
  17.       creates an Expect script that    reproduces your    interactions.
  18.       For straightline scripts, autoexpect saves substantial time
  19.       over writing scripts by hand.     Even if you are an Expect
  20.       expert, you will find    it convenient to use autoexpect    to
  21.       automate the more mindless parts of interactions.  It    is
  22.       much easier to cut/paste hunks of autoexpect scripts
  23.       together than    to write them from scratch.  And if you    are a
  24.       beginner, you    may be able to get away    with learning nothing
  25.       more about Expect than how to    call autoexpect.
  26.  
  27.       The simplest way to use autoexpect is    to call    it from    the
  28.       command line with no arguments.  For example:
  29.  
  30.            % autoexpect
  31.  
  32.       By default, autoexpect spawns    a shell    for you.  Given    a
  33.       program name and arguments, autoexpect spawns    that program.
  34.       For example:
  35.  
  36.            % autoexpect ftp    ftp.cme.nist.gov
  37.  
  38.       Once your spawned program is running,    interact normally.
  39.       When you have    exited the shell (or program that you
  40.       specified), autoexpect will create a new script for you.  By
  41.       default, autoexpect writes the new script to "script.exp".
  42.       You can override this    with the -f flag followed by a new
  43.       script name.
  44.  
  45.       The following    example    runs "ftp ftp.cme.nist.gov" and    stores
  46.       the resulting    Expect script in the file "nist".
  47.  
  48.            % autoexpect -f nist ftp    ftp.cme.nist.gov
  49.  
  50.       It is    important to understand    that autoexpect    does not
  51.       guarantee a working script because it    necessarily has    to
  52.       guess    about certain things - and occasionally    it guesses
  53.       wrong.  However, it is usually very easy to identify and fix
  54.       these    problems.  The typical problems    are:
  55.  
  56.            +o   Timing.  A surprisingly large number    of programs
  57.            (rn,    ksh, zsh, telnet, etc.)    and devices (e.g.,
  58.            modems) ignore keystrokes that arrive "too quickly"
  59.            after prompts.  If you find your new    script hanging
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 12/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))     UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((33330000 JJJJuuuunnnneeee 1111999999995555))))     AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))
  71.  
  72.  
  73.  
  74.            up at one spot, try adding a    short sleep just
  75.            before the previous send.
  76.  
  77.            You can force this behavior throughout by
  78.            overriding the variable "force_conservative"    near
  79.            the beginning of the    generated script.  This
  80.            "conservative" mode makes autoexpect    automatically
  81.            pause briefly (one tenth of a second) before
  82.            sending each    character.  This pacifies every
  83.            program I know of.
  84.  
  85.            This    conservative mode is useful if you just    want
  86.            to quickly reassure yourself    that the problem is a
  87.            timing one (or if you really    don't care about how
  88.            fast    the script runs).  This    same mode can be
  89.            forced before script    generation by using the    -c
  90.            flag.
  91.  
  92.            Fortunately,    these timing spots are rare.  For
  93.            example, telnet ignores characters only after
  94.            entering its    escape sequence.  Modems only ignore
  95.            characters immediately after    connecting to them for
  96.            the first time.  A few programs exhibit this
  97.            behavior all    the time but typically have a switch
  98.            to disable it.  For example,    rn's -T    flag disables
  99.            this    behavior.
  100.  
  101.            The following example starts    autoexpect in
  102.            conservative    mode.
  103.  
  104.             autoexpect -c
  105.  
  106.            The -C flag defines a key to    toggle conservative
  107.            mode. The following example starts autoexpect (in
  108.            non-conservative mode) with ^L as the toggle.
  109.            (Note that the ^L is    entered    literally - i.e.,
  110.            enter a real    control-L).
  111.  
  112.             autoexpect -C ^L
  113.  
  114.            The following example starts    autoexpect in
  115.            conservative    mode with ^L as    the toggle.
  116.  
  117.             autoexpect -c -C ^L
  118.  
  119.  
  120.            +o   Echoing.  Many program echo characters.  For
  121.            example, if you type    "more" to a shell, what
  122.            autoexpect actually sees is:
  123.  
  124.             you typed 'm',
  125.             computer typed 'm',
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 12/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))     UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((33330000 JJJJuuuunnnneeee 1111999999995555))))     AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))
  137.  
  138.  
  139.  
  140.             you typed 'o',
  141.             computer typed 'o',
  142.             you typed 'r',
  143.             computer typed 'r',
  144.             ...
  145.  
  146.            Without specific knowledge of the program, it is
  147.            impossible to know if you are waiting to see    each
  148.            character echoed before typing the next.  If
  149.            autoexpect sees characters being echoed, it assumes
  150.            that    it can send them all as    a group    rather than
  151.            interleaving    them the way they originally appeared.
  152.            This    makes the script more pleasant to read.
  153.            However, it could conceivably be incorrect if you
  154.            really had to wait to see each character echoed.
  155.  
  156.  
  157.            +o   Change.  Autoexpect records every character from
  158.            the interaction in the script.  This    is desirable
  159.            because it gives you    the ability to make judgements
  160.            about what is important and what can    be replaced
  161.            with    a pattern match.
  162.  
  163.            On the other    hand, if you use commands whose    output
  164.            differs from    run to run, the    generated scripts are
  165.            not going to    be correct.  For example, the "date"
  166.            command always produces different output.  So using
  167.            the date command while running autoexpect is    a sure
  168.            way to produce a script that    will require editing
  169.            in order for    it to work.
  170.  
  171.            The -p flag puts autoexpect into "prompt mode".  In
  172.            this    mode, autoexpect will only look    for the    the
  173.            last    line of    program    output - which is usually the
  174.            prompt.  This handles the date problem (see above)
  175.            and most others.
  176.  
  177.            The following example starts    autoexpect in prompt
  178.            mode.
  179.  
  180.             autoexpect -p
  181.  
  182.            The -P flag defines a key to    toggle prompt mode.
  183.            The following example starts    autoexpect (in non-
  184.            prompt mode)    with ^P    as the toggle.    Note that the
  185.            ^P is entered literally - i.e., enter a real
  186.            control-P.
  187.  
  188.             autoexpect -P ^P
  189.  
  190.            The following example starts    autoexpect in prompt
  191.            mode    with ^P    as the toggle.
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 12/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))     UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((33330000 JJJJuuuunnnneeee 1111999999995555))))     AAAAUUUUTTTTOOOOEEEEXXXXPPPPEEEECCCCTTTT((((1111))))
  203.  
  204.  
  205.  
  206.             autoexpect -p -P ^P
  207.  
  208.  
  209.      OOOOTTTTHHHHEEEERRRR FFFFLLLLAAAAGGGGSSSS
  210.       The ----qqqquuuuiiiieeeetttt flag disables informational messages produced by
  211.       autoexpect.
  212.  
  213.       The ----QQQQ flag names a quote character which can    be used    to
  214.       enter    characters that    autoexpect would otherwise consume
  215.       because they are used    as toggles.
  216.  
  217.       The following    example    shows a    number of flags    with quote
  218.       used to provide a way    of entering the    toggles    literally.
  219.  
  220.            autoexpect -P ^P    -C ^L -Q ^Q
  221.  
  222.  
  223.      SSSSTTTTYYYYLLLLEEEE
  224.       I don't know if there    is a "style" for Expect    programs but
  225.       autoexpect should definitely not be held up as any model of
  226.       style.  For example, autoexpect uses features    of Expect that
  227.       are intended specifically for    computer-generated scripting.
  228.       So don't try to faithfully write scripts that    appear as if
  229.       they were generated by autoexpect.  This is not useful.
  230.  
  231.       On the other hand, autoexpect    scripts    do show    some
  232.       worthwhile things.  For example, you can see how any string
  233.       must be quoted in order to use it in a Tcl script simply by
  234.       running the strings through autoexpect.
  235.  
  236.  
  237.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  238.       "_E_x_p_l_o_r_i_n_g _E_x_p_e_c_t: _A _T_c_l-_B_a_s_e_d _T_o_o_l_k_i_t _f_o_r _A_u_t_o_m_a_t_i_n_g
  239.       _I_n_t_e_r_a_c_t_i_v_e _P_r_o_g_r_a_m_s"    by Don Libes, O'Reilly and Associates,
  240.       January 1995.
  241.  
  242.      AAAAUUUUTTTTHHHHOOOORRRR
  243.       Don Libes, National Institute    of Standards and Technology
  244.  
  245.       eeeexxxxppppeeeecccctttt and aaaauuuuttttooooeeeexxxxppppeeeecccctttt    are in the public domain.  NIST    and I
  246.       would    appreciate credit if these programs or parts of    them
  247.       are used.
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 12/23/98)
  262.  
  263.  
  264.  
  265.